//
//  YWAttendanceRecord.m
//  maintain
//
//  Created by 郑想 on 16/2/22.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWAttendanceRecord.h"
#import "MJExtension.h"
#import "NSDate+Additions.h"
#import "YWCommonTool.h"
#import "YWLocation.h"
#import "YWHandler.h"
#import "YWReply.h"

@implementation YWAttendanceRecord
+ (NSDictionary*)mj_replacedKeyFromPropertyName
{
    return @{ @"arriveTime" : @"createTime",
              @"arriveRemark" : @"note",
              @"locationText" : @"position",
              @"recordId" : @"attendanceRecordId"};
}

+ (NSDictionary*)mj_objectClassInArray
{
    return @{ @"pictures" : @"YWPatrolPicture",
              @"observers" : @"YWHandler",
              @"replies" : @"YWReply"};
}

- (void)mj_keyValuesDidFinishConvertingToObject{
    NSTimeInterval sytemTime = self.arriveTime/1000;
    
    NSDate* attendanceDate = [NSDate dateWithTimeIntervalSince1970:sytemTime];
    self.yearMonthDay = [[NSString stringWithFormat:@"%ld%.2ld%.2ld", (long)attendanceDate.year, (long)attendanceDate.month,(long)attendanceDate.day] integerValue];
    ;
    self.dateShow = [NSString stringWithFormat:@"%.2ld月%.2ld日 %@", (long)attendanceDate.month, (long)attendanceDate.day, [YWCommonTool weekDayString:attendanceDate.weekday - 1]];
    if (self.location) {
        self.locationId = self.location.locationId;
    }
    
    NSMutableString *observerIds = [[NSMutableString alloc] init];
    [self.observers enumerateObjectsUsingBlock:^(YWHandler*  _Nonnull handler, NSUInteger idx, BOOL * _Nonnull stop) {
        if (idx!=0) {
            [observerIds appendString:@","];
        }
        [observerIds appendString:[@(handler.uniqueId) stringValue]];
    }];
    self.observerIds = [NSString stringWithFormat:@"%@",observerIds];
}

@end
